<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.text.SimpleDateFormat"%>  
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.ResultSet"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加结果</title>
</head>
<body>
	<jsp:useBean id="Connection1" class="conn.Connection1"></jsp:useBean>
	<jsp:setProperty property="*" name="Connection1"/>
	<%
		try {
			Connection conn = Connection1.getConnection();
			String username = new String(request.getParameter("username"));
			String pwd = new String(request.getParameter("password"));
			boolean flag = true ;
			// 获取Statement
			Statement stmt = conn.createStatement();
			// 添加图书信息的SQL语句
			String sql = "select  * from user where name='"+ username + "'and password='" + pwd + "'";
			// 执行查询
			ResultSet rs = stmt.executeQuery(sql);// 执行SQL语句
			if(rs.next()){
				// out.print("rs"+rs);
				//request.getRequestDispatcher("indexEnd.jsp").forward(request, response);
				session.setAttribute("username",username);
				session.setMaxInactiveInterval(5*60);
				response.sendRedirect("indexFront.jsp");
			}else{
				flag = false ; 
				request.setAttribute("flag",flag);
				//response.sendRedirect("login.jsp");
				request.getRequestDispatcher("login.jsp").forward(request,response);
			}
			// 关闭PreparedStatement，释放资源
			conn.close();
		} catch (Exception e) {
			out.print("登录失败！");
			e.printStackTrace();
		}
	%>
</body>
</html>